package com.ybg.common.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@ApiModel("后端返回前端统一数据格式Message：消息")
@Data
public abstract class Message {
    public static Message succeed(Object data){
        return new Message(MessageStatus.MS200,data){};
    }

    public static Message fail(String...reason){
        return new Message(MessageStatus.MS201,reason[0]){};
    }

    public static Message repeat(String data){
        return new Message(MessageStatus.MS202,data){};
    }

    public static Message error(Throwable data){
        return new Message(MessageStatus.MS500,data.getMessage()){};
    }

    @ApiModelProperty("status: 消息状态")
    private MessageStatus status;
    @ApiModelProperty("data : 消息内容(基于Object多态，可以兼容一切类型)")
    private Object data;

    private Message(MessageStatus status, Object data) {
        this.status = status;
        this.data = data;
    }

}
